package algorithm;

public class Empress8 {

    private int[] arr;
    private int count;
    private int N;
    public Empress8(int N){
        this.N=N;
        this.arr=new int[N];
        this.count=0;
        check(0);
        System.out.println(count);
    }
    void print(){
        for (int i = 0; i < N; i++) {
            System.out.print(arr[i]+" ");
        }
        System.out.println();
    }
    boolean juge(int n){
        for (int i = 0; i < n; i++) {
            if(arr[i]==arr[n] || Math.abs(arr[i]-arr[n])==Math.abs(i-n)){
                return false;
            }
        }
        return true;
    }

    public void check(int n){
        if(n==8){
            print();
            count++;
            return;
        }
        for (int i = 0; i < N; i++) {
            arr[n]=i;
            if(juge(n)){
                check(n+1);
            }
        }
    }



}
